package slidingwindow.leetcode_239_slidingwindow;

public class ForSolution {
    public int[] maxSlidingWindow(int[] nums, int k) {
        int len = nums.length;
        //特殊情况
        if (nums == null || len == 0 || k == 0 || k > len) {
            return new int[0];
        }
        int res[] = new int[len - k + 1];
        //窗口的左边界 i
        for (int i = 0; i + k - 1 < len; i++) {
            //根据左边界计算出窗口的右边界
            int right = i + k - 1;
            //遍历窗口中的所有元素，寻找最大值
            int max = nums[right];
            for (int left = i; left < right; left++) {
                max = Math.max(max, nums[left]);
            }
            res[i] = max;
        }
        return res;
    }
}
